<?php

namespace App\Admin\Controllers;

use App\Models\Address;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;



class AddressController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '地址管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Address);

        $grid->column('Id', __('Id'));
        $grid->column('name', __('用户名'));
        // $grid->column('computing', __('单台算力'));
        // $grid->column('power_consumption', __('功耗'));
        //$grid->column('power_ratio', __('功耗比'));
        $grid->column('telephone', __('电话'));
        // $grid->column('electricity_fee', __('每T算力的电费'));
        $grid->column('detailed', __('详细地址'));
        $grid->column('created_at', __('添加时间'));
//        $grid->column('status', __('状态'))->display(function ($status) {
//            return config('conf.status')[$status];
//        });
//        $grid->column('stock', __('商品价格'));
//        $grid->column('sold', __('销售量'));



        // $grid->column('computing_stock', __('剩余算力数量'));
        // $grid->column('sell_computing', __('卖出算力'));
        //  $grid->column('income', __('每T算力的收益'));
    //   $grid->column('sort', __('排序'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Address::findOrFail($id));
        $show->field('id', __('Id'));
        $show->field('name', __('用户名'));
        // $show->field('computing', __('Computing'));
        // $show->field('power_consumption', __('Power consumption'));
        //$show->field('power_ratio', __('Power ratio'));
        $show->field('uid', __('用户ID'));
        $show->field('telephone', __('联系方式'));
        $show->field('province', __('省'));
        $show->field('city', __('市'));
        $show->field('area', __('区'));
        $show->field('detailed', __('详细地址'));
        //$show->field('electricity_fee', __('Electricity fee'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Address);

        $form->text('name', __('用户名'));
        $form->image('telephone','联系方式');
        // $form->text('computing', __('单台算力'));
        //$form->text('power_consumption', __('功耗'));
        //$form->text('power_ratio', __('功耗比'));

        $form->select('original', __('默认'))->options(config('conf.original'));
//        $data=Commoditytype::all()->toArray();
//        foreach ($data as $item){
//            $_item=$item["Id"];
//            $_item1=$item["name"];
//            $arr[$_item]=$_item1;
//        }
//        $form->select('type', __('类型'))->options($arr);
//        $form->select('status', __('状态'))->options(config('conf.status'));
//        // $form->number('computing_stock', __('剩余算力'));
//        // $form->number('sell_computing', __('卖出算力'));
//        // $form->decimal('income', __('每T算力的收益'));
//        $form->number('sort', __('排序'));
//        //$form->number('cycle', __('周期'));
//        $form->ueditor('rule', '商品描述');
        return $form;
    }
}
